package com.nf.practice.streamlambdatest;

import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: KeepFresh
 * @time: 2022/4/27 11:37
 */
public class StreamSort {

    @Test
    public void test3() {
        List<Map<String, Object>> big5BuyidHongChong24m_list = new ArrayList<>();
        JSONArray big5_buyid_hong_chong_24mTotalList = new JSONArray();
        big5_buyid_hong_chong_24mTotalList.add("-890.0");
        for (int i = 0; i < big5_buyid_hong_chong_24mTotalList.size(); i++) {
            Map<String, Object> big5_buyid_hong_chong_24m_map = new HashMap<>();
            big5_buyid_hong_chong_24m_map.put("total", BigDecimal.valueOf(Double.valueOf(big5_buyid_hong_chong_24mTotalList.get(i).toString())));
            big5BuyidHongChong24m_list.add(big5_buyid_hong_chong_24m_map);
        }
        System.out.println(big5BuyidHongChong24m_list);
    }

    @Test
    public void test2() {
        List<Integer> list=new ArrayList<>();
        list.add(1);
        list.add(1);
        list.add(3);
        list.add(2130);
        list.add(38);
        list=list.stream().filter(v -> (v >= 1)).collect(Collectors.toList());
        for (Integer integer : list) {
            System.out.println(integer);
        }
    }


    @Test
    public void test() {
        List<EqpUPHVO> eqpUPHVOS = new ArrayList<>();
        EqpUPHVO eqpUPHVO = new EqpUPHVO();
        eqpUPHVO.setEqpName("ffff");
        eqpUPHVO.setUphData(BigDecimal.valueOf(34343));
        eqpUPHVOS.add(eqpUPHVO);

        eqpUPHVO = new EqpUPHVO();
        eqpUPHVO.setEqpName("gdg");
        eqpUPHVO.setUphData(BigDecimal.valueOf(23343));
        eqpUPHVOS.add(eqpUPHVO);

        eqpUPHVO = new EqpUPHVO();
        eqpUPHVO.setEqpName("qq");
        eqpUPHVO.setUphData(BigDecimal.valueOf(22));
        eqpUPHVOS.add(eqpUPHVO);

        eqpUPHVO = new EqpUPHVO();
        eqpUPHVO.setEqpName("gdererg");
        eqpUPHVO.setUphData(BigDecimal.valueOf(343534545));
        eqpUPHVOS.add(eqpUPHVO);

        eqpUPHVO = new EqpUPHVO();
        eqpUPHVO.setEqpName("gdfgg");
        eqpUPHVO.setUphData(BigDecimal.valueOf(33));
        eqpUPHVOS.add(eqpUPHVO);
        System.out.println(eqpUPHVOS);

        System.out.println("-----------------------");
        // 求最大值
        BigDecimal maxUPH = eqpUPHVOS.stream().max(Comparator.comparing(EqpUPHVO::getUphData)).get().getUphData();
        System.out.println(maxUPH);
        System.out.println("==============");
        // 根据uph值进行排序 使用reversed() 实现从大到小排列
        List<EqpUPHVO> maxUPHs = eqpUPHVOS.stream().sorted(Comparator.comparing(EqpUPHVO::getUphData).reversed())
                .collect(Collectors.toList());
        System.out.println(maxUPHs);
        System.out.println("==============");
        // 根据uph值进行排序 使用sorted() 默认从小到大即升序排列
        List<EqpUPHVO> maxUPHss =
                eqpUPHVOS.stream().sorted(Comparator.comparing(EqpUPHVO::getUphData)).collect(Collectors.toList());
        System.out.println(maxUPHss);
    }
}
